class D:

    def __setattr__(self, key, value):
        # 这样的实现是有问题的
        self.key = value


d = D()


# d.name = '小甲鱼'


# 上面的新增属性 name 会报错
#   [Previous line repeated 996 more times]
# RecursionError: maximum recursion depth exceeded
# 由于我们的实现是 self.key = value,导致了无限递归，死循环了


class E:

    def __setattr__(self, key, value):
        self.__dict__[key] = value


e = E()
e.name = '小甲鱼'
print(e.name)
